<template>
	<view class="container">
		<uni-section title="搜索" type="line" v-if="checkRole(['manager'])"></uni-section>
		<view class="query-form" v-if="checkRole(['manager'])">
			<view class="query-time">
				<uni-easyinput v-model="queryParams.coachName" placeholder="请输入教练姓名" />
			</view>
			<view class="query-item">
				<button class="uni-button" size="mini" type="primary" @click="handleQuery">搜索</button>
			</view>
		</view>
		<uni-section :title="'教练信息:共 ' + total + ' 人'" type="line"></uni-section>
		<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
			<uni-tr>
				<uni-th align="center">教练信息</uni-th>
				<uni-th width="250rpx" align="center">操作</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in tableList" :key="index">
				<uni-td>
					<view class="name">教练姓名: {{ item.coachName }}</view>
					<view class="name">底薪: {{ item.salaryBasic }}</view>
					<view class="name">课时费: {{ item.classFee }}</view>
					<view class="name">入职时间: {{ parseTime(item.joinTime, '{y}-{m}-{d}') }}</view>
					<view class="name remark">{{ item.remark }}</view>
				</uni-td>
				<uni-td align="center">
					<view v-if="checkPermi(['puyu:coach:edit'])">
						<button class="uni-button" size="mini" type="primary"
							@click="handleEditCoach(item)">修改</button>
					</view>
					<view v-if="checkPermi(['puyu:lesson:list'])">
						<button class="uni-button" size="mini" @click="handleCoachLesson(item)"
							style="color:#ffffff;backgroundColor:#993399;borderColor:#993399; height: 80rpx; padding: 10rpx 40rpx;">课时</button>
					</view>
					<view v-if="checkPermi(['puyu:coach:remove'])">
						<button class="uni-button" size="mini" type="warn"
							@click="handleDeleteCoach(item)">删除</button>
					</view>
				</uni-td>
			</uni-tr>
		</uni-table>
		<uni-pagination :page-size="queryParams.pageSize" :current="queryParams.pageNum" :total="total" @change="change"
			prev-text="前一页" next-text="后一页" />
		<view class="page-sum">
			<view>当前页：{{ queryParams.pageNum }}，数据总量：{{ total }} 条，每页数据：{{ queryParams.pageSize }} 条</view>
		</view>
	</view>
</template>

<script>
	import { checkPermi, checkRole } from "@/utils/permission";
  import { listCoach, delCoach } from "@/api/puyu/coach";
	import { parseTime } from '@/utils/common';
	export default {
		data() {
			return {
				// 遮罩层
				loading: true,
				// 总条数
				total: 0,
				// 体能测试表格数据
				tableList: null,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 5,
					coachId: null,
					coachName: null,
				},
			}
		},
		computed: {
		},
		created() {
		},
		onShow() {
			this.getList();
		},
		methods: {
			checkPermi,
			checkRole,
			parseTime,
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 查询课时点名列表 */
			getList() {
				this.loading = true;
				this.queryParams.orderByColumn = 'coachId'; //查询字段是表格中字段名字
				this.queryParams.isAsc = 'descending'; //动态取值排序顺序
				listCoach(this.queryParams).then(response => {
					this.tableList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			/** 修改教练信息*/
			handleEditCoach(item) {
				this.$tab.navigateTo('/pages/puyu/coach/edit?item=' + encodeURIComponent(JSON.stringify(item)));
			},
			/** 进入教练课时列表*/
			handleCoachLesson(item) {
				this.$tab.navigateTo('/pages/puyu/coach/coach-lesson?coachId=' + item.coachId);
			},
			/** 删除教练信息*/
			handleDeleteCoach(item) {
				const coachIds = item.coachId;
				this.$modal.confirm('是否确认删除教练ID为"' + coachIds + '"的数据项？').then(function() {
				  return delCoach(coachIds);
				}).then(() => {
				  this.getList();
				  this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.getData(e.current)
			},
			// 获取数据
			getData(pageCurrent, value = '') {
				this.queryParams.pageNum = pageCurrent
				this.getList()
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifndef H5 */
	/* page {
	padding-top: 85px;
} */
	/* #endif */

	.page-sum {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.query-form {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		background-color: #ffffff;
		margin-bottom: 10px;
	}

	.query-item {
		margin: 5rpx;
		padding: 5rpx;
	}

	.query-time {
		margin: 5rpx;
		padding: 5rpx;
	}
	
	.query-item-value {
		margin-top: 5rpx;
		color: darkgray;
	}
	.remark {
		color: #993399;
		font-weight: bolder;
	}
	.status-green {
		color: #00aa00;
		font-weight: bolder;
	}
	.status-yellow {
		color: #ffff00;
		font-weight: bolder;
	}
	.status-red {
		color: #ff0000;
		font-weight: bolder;
	}
</style>